gdk_texture_new_from_bytes (GBytes *bytes,
GError **error)
{
- const char *data;
- gsize size;
-
g_return_val_if_fail (bytes != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
- data = g_bytes_get_data (bytes, &size);
-
- if (size > strlen (PNG_SIGNATURE) &&
- memcmp (data, PNG_SIGNATURE, strlen (PNG_SIGNATURE)) == 0)
+ if (gdk_is_png (bytes))
{
return gdk_load_png (bytes, error);
}
- else if ((size > strlen (TIFF_SIGNATURE1) &&
- memcmp (data, TIFF_SIGNATURE1, strlen (TIFF_SIGNATURE1)) == 0) ||
- (size > strlen (TIFF_SIGNATURE2) &&
- memcmp (data, TIFF_SIGNATURE2, strlen (TIFF_SIGNATURE2)) == 0))
+ else if (gdk_is_jpeg (bytes))
{
- return gdk_load_tiff (bytes, error);
+ return gdk_load_jpeg (bytes, error);
}
- else if (size > strlen (JPEG_SIGNATURE) &&
- memcmp (data, JPEG_SIGNATURE, strlen (JPEG_SIGNATURE)) == 0)
+ else if (gdk_is_tiff (bytes))
{
- return gdk_load_jpeg (bytes, error);
+ return gdk_load_tiff (bytes, error);
}
else
{
GInputStream *stream;
GdkPixbuf *pixbuf;
+ GdkTexture *texture;
stream = g_memory_input_stream_new_from_bytes (bytes);
pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, error);
g_object_unref (stream);
+ if (pixbuf == NULL)
+ return NULL;
- if (pixbuf)
- {
- GdkTexture *texture;
-
- texture = gdk_texture_new_for_pixbuf (pixbuf);
- g_object_unref (pixbuf);
+ texture = gdk_texture_new_for_pixbuf (pixbuf);
+ g_object_unref (pixbuf);
- return texture;
- }
+ return texture;
}
-
- return NULL;
}
/**
GdkTexture *gdk_load_jpeg (GBytes *bytes,
GError **error);
+static inline gboolean
+gdk_is_jpeg (GBytes *bytes)
+{
+ const char *data;
+ gsize size;
+
+ data = g_bytes_get_data (bytes, &size);
+
+ return size > strlen (JPEG_SIGNATURE) &&
+ memcmp (data, JPEG_SIGNATURE, strlen (JPEG_SIGNATURE)) == 0;
+}
+
#endif
GBytes * gdk_save_tiff (GdkTexture *texture);
+static inline gboolean
+gdk_is_tiff (GBytes *bytes)
+{
+ const char *data;
+ gsize size;
+
+ data = g_bytes_get_data (bytes, &size);
+
+ return (size > strlen (TIFF_SIGNATURE1) &&
+ memcmp (data, TIFF_SIGNATURE1, strlen (TIFF_SIGNATURE1)) == 0) ||
+ (size > strlen (TIFF_SIGNATURE2) &&
+ memcmp (data, TIFF_SIGNATURE2, strlen (TIFF_SIGNATURE2)) == 0);
+}
+
#endif